function C.GetColormod( ply, planet )
	
	if( planet > 0 ) then
		
		local colorid = C.MapObjects.Planets[planet].colorid;
		
		for k, v in pairs( C.MapObjects.Colors ) do
			
			if( v.id == colorid ) then
				
				return k;
				
			end
			
		end
		
	end
	
	return 0;
	
end

function C.GetBloom( ply, planet )
	
	if( planet > 0 ) then
		
		local bloomid = C.MapObjects.Planets[planet].bloomid;
		
		for k, v in pairs( C.MapObjects.Blooms ) do
			
			if( v.id == bloomid ) then
				
				return k;
				
			end
			
		end
		
	end
	
	return 0;
	
end

function GM:RenderScreenspaceEffects()
	
	if( !LocalPlayer():Alive() ) then return end
	
	local planet = C.InPlanet( LocalPlayer() ) or 1;
	local colormod = C.GetColormod( LocalPlayer(), planet );
	local bloom = C.GetBloom( LocalPlayer(), planet );
	
	if( colormod > 0 ) then
		
		local color = C.MapObjects.Colors[colormod];
		
		local cmod = { };
		cmod["$pp_colour_addr"] = color.addcol.x;
		cmod["$pp_colour_addg"] = color.addcol.y;
		cmod["$pp_colour_addb"] = color.addcol.z;
		cmod["$pp_colour_brightness"] = color.brightness;
		cmod["$pp_colour_contrast"] = color.contrast;
		cmod["$pp_colour_colour"] = color.color;
		cmod["$pp_colour_mulr"] = color.mulcol.x;
		cmod["$pp_colour_mulg"] = color.mulcol.y;
		cmod["$pp_colour_mulb"] = color.mulcol.z;
		
		DrawColorModify( cmod );
		
	end
	
	if( bloom > 0 ) then
		
		local blom = C.MapObjects.Blooms[bloom];
		DrawBloom( blom.darken, blom.multiply, blom.x, blom.y, blom.passes, blom.colormul, blom.color.x, blom.color.y, blom.color.z );
		
	end
	
end

local Laser = Material( "cable/physbeam" );

function GM:PostDrawTranslucentRenderables()
	
	if( LocalPlayer():Alive() ) then
		
		local wep = LocalPlayer():GetActiveWeapon();
		
		if( wep and wep:IsValid() and wep:GetClass() == "gmod_tool" ) then
			
			render.SetMaterial( Laser );
			
			for _, v in pairs( ents.GetAll() ) do
				
				if( v.Cosmic ) then
					
					if( !v.Links ) then v.Links = { } end
					
					local linktab = v.Links;
					
					for _, n in pairs( linktab ) do
						
						if( n and n:IsValid() ) then
							
							render.DrawBeam( v:GetPos(), n:GetPos(), 6, 0, 0, Color( 255, 255, 255, 255 ) );
							
						end
						
					end
					
				end
				
			end
			
		end
		
	end
	
end